<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试机申请</title>
<import file="js.My97DatePicker.WdatePicker" />
<import file="js.jquery" />
<import type="css" file="css.workform" />
</head>

<body>
<form action="__URL__/apply_insert" method="post" name="form1" onsubmit="return CheckForm();">
  <div style="width: 725px;margin: 0 auto;text-align: right;padding-bottom: 10px">
    <span style="width:725px;text-align:right;">直属销售: <input type="text" size="10" name="higher" class="BigInput apply" value="{$data['higher']}"></span>
  </div>
  <table align="center" border="0" width="725" cellpadding="2" cellspacing="1" align="center" bgcolor="#000000" class="TableBlock">
    <tr>
    	<td class="TableContent">申请人</td>
    	<td class="TableData"><input type="text" name="apply_username" size="23" class="BigInpu apply" value="{$data['apply_username']}" ></td>
    	<td class="TableContent">申请日期</td>
    	<td class="TableData"><input type="text" name="apply_date" size="23" class="BigInpu apply" onClick="WdatePicker()" value="{$data.apply_date}" ></td>
    </tr>
    <tr>
     <td nowrap class="TableContent"> 设备类型：</td>
      <td class="TableData" nowrap colspan="3">
        <input type="radio" name="type" value="1" <if condition="$data['type'] eq '1'">checked</if> >统一安全管理与综合审计系统&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="radio" name="type" value="2" <if condition="$data['type'] eq '2'">checked</if> >数据库审计系统
      </td>
    </tr>
    <tr>
     <td nowrap class="TableContent"> 产品型号：</td>
      <td class="TableData" nowrap colspan="3">
        <select name="model" style="width: 180px;" class="apply">
      		
      	</select>
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 功能需求：</td>
      <td class="TableData" colspan="3">
        <textarea rows="4" cols="50" name="demand">{$data.demand}</textarea>
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 客户名称：</td>
      <td class="TableData" colspan="3">
        <input type="text" name="client_name" size="64" value="{$data.client_name}" class="BigInput apply" >
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 合作伙伴：</td>
      <td class="TableData" colspan="3">
      	<textarea rows="4" cols="50" name="partner" >{$data.partner}</textarea>
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 测试地点：</td>
      <td class="TableData" colspan="3">
        <input type="text" name="place" size="40" value="{$data.place}" class="BigInput apply" >
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 预计归还时间：</td>
      <td class="TableData" colspan="3">
        <input type="text" name="back_time" size="23" class="BigInput apply" value="{$data.back_time}" onClick="WdatePicker()" >&nbsp;&nbsp;共计借测&nbsp;&nbsp;<input type="text" name="back_weekly" size="4" value="{$data.back_weekly}" class="BigInput apply" >&nbsp;&nbsp;周
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 申请原因：</td>
      <td class="TableData" colspan="3">
        <textarea rows="4" cols="50" name="reason" >{$data.reason}</textarea>
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 负责人签字：</td>
      <td class="TableData" colspan="3">
      	<input type="text" name="higher_sign" size="64" value="{$data.higher_sign}" class="BigInput sign" >
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 公司审批：</td>
      <td class="TableData" colspan="3">
        <input type="radio" name="audit" value="1"  <if condition="$data['audit'] eq '1'">checked</if> >同意&nbsp;&nbsp;&nbsp;&nbsp;<br>
        <input type="radio" name="audit" value="2"  <if condition="$data['audit'] eq '2'">checked</if> >不同意
		<label id="audit_reason" style="display: none">理由<input type="text" name="audit_reason" size="64" value="{$data.audit_reason}" class="BigInput audit_reason" ></label>
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 设备序列号：</td>
      <td class="TableData" colspan="3">
        <input type="text" name="serial_number" size="64" value="{$data.serial_number}" class="BigInput business" >
      </td>
    </tr>
    <tr class="TableControl">
      <td nowrap colspan="4" align="center">
      	<input type="hidden" value="{$action}" name="action" >
      	<input type="hidden" value="{$data.id}" name="id" >
      	<input type="hidden" value="{$data.status}" name="status" >
      	<input type="hidden" value="{$data.dept_id}" name="dept_id" >
      	<input type="hidden" value="1" name="way" >
        <input type="submit" value="保存" onclick="changeway(1)" class="BigButton">&nbsp;&nbsp;&nbsp;
        <input type="submit" value="提交" onclick="changeway(2)" class="BigButton">&nbsp;&nbsp;&nbsp;
      </td>
    </tr>
    </table>
</form>

</body>
<script type="text/javascript">
	$(document).ready(function(){
		var action = "{$action}";
		var apply_same = "{$data['apply_same']}";
		if(action == "apply"){
			$(".business").attr('disabled',true);
			$(".business").css("background-color","#F2F2F2");
			$("input[name='audit']").attr('disabled',true); 
			$(".audit_reason").attr('disabled',true); 
			$(".audit_reason").css("background-color","#F2F2F2"); 
			if(apply_same != '1'){
				$("input[name='higher_sign']").attr('disabled',true); 
				$("input[name='higher_sign']").css("background-color","#F2F2F2"); 
			}else{
				$("input[name='higher_sign']").val("{$data.apply_username}");
			}
		}else if(action == 'sign'){
			$(".apply").attr('disabled',true);
			$(".apply").css("background-color","#F2F2F2");
			$("input[type='radio']").attr('disabled',true); 
			$(".business").attr('disabled',true);
			$(".business").css("background-color","#F2F2F2");
			$("textarea").attr('disabled',true);
			$("textarea").css("background-color","#F2F2F2");
			$(".audit_reason").attr('disabled',true);
		}else if(action == 'audit'){
			$(".apply").attr('disabled',true);
			$(".apply").css("background-color","#F2F2F2");
			$("input[name='type']").attr('disabled',true); 
			$(".business").attr('disabled',true);
			$(".business").css("background-color","#F2F2F2");
			$(".sign").attr('disabled',true);
			$(".sign").css("background-color","#F2F2F2");
			$("textarea").attr('disabled',true);
			$("textarea").css("background-color","#F2F2F2");
		}else if(action == 'send'){
			$(".apply").attr('disabled',true);
			$(".apply").css("background-color","#F2F2F2");
			$("input[type='radio']").attr('disabled',true); 
			$(".sign").attr('disabled',true);
			$(".sign").css("background-color","#F2F2F2");
			$("textarea").attr('disabled',true);
			$("textarea").css("background-color","#F2F2F2");
			$(".audit_reason").attr('disabled',true);
			$(".audit_reason").css("background-color","#F2F2F2");
		}
		
		
		
		$("input[name='audit']").click(function (){
			var audit = $(this).val();
			if(audit == '2'){
				$("#audit_reason").css("display", "block");
			}else{
				$("#audit_reason").css("display", "none");
				$("input[name='audit_reason']").val("");
			}
		});
		if( $("input[name='audit']:checked").val() == '2' ){
			$("#audit_reason").css("display", "block");
		}
		
		$("input[name='type']:radio").change(function(){
			checkradio();
		});
		checkradio();
	});
	function changeway(value){
		$("input[name='way']").val(value);
	}
	
	function checkradio(){
		var type = $("input[name='type']:radio:checked").val();
		if(type == undefined){
			return false;
		}
		var model = "{$data.model}";
		$.getJSON("__APP__/Device/gettype?type="+type,function(result){
			$("select[name='model'] option").remove();
			$.each(result, function(i,value){
				if(value.id == model){
					$("select[name='model']").append("<option value='"+value.id+"' selected>"+value.name);
				}else{
					$("select[name='model']").append("<option value='"+value.id+"'>"+value.name);
				}
			});
		});
	}
	function CheckForm(){
		var action = $("input[name='action']").val();
		if( action == 'apply' ){
			var higher = $("input[name='higher']").val();
			var apply_username = $("input[name='apply_username']").val();
			var back_weekly = $("input[name='back_weekly']").val();
			
			if( apply_username == '' ){
				alert("请填写申请人！");return false;
			}
			if( higher == '' ){
				alert("请填写直属销售姓名！");return false;
			}
			//检测申请时间
			var apply_date = $("input[name='apply_date']").val();
			var back_time = $("input[name='back_time']").val();
			if(apply_date == ''){
				alert("请选择申请时间！");return false;
			}
			var time = parseInt(apply_date.replace(/-/g, ""));
			var backtime = parseInt(back_time.replace(/-/g, ""));//归还时间
			var date = new Date();
			var month = date.getMonth()+1;
			var dat = date.getDate();
			
			if(month < 10){
				month = "0"+month;
			}
			if( dat < 10 ){
				dat = "0"+dat;
			}
			var today = date.getFullYear()+''+month+''+dat;
			if( time < today){
				alert("申请日期必须要大于或等于当前日期！");return false;
			}
			
			
			var type = $("input[name='type']:checked").val();
			if( type != 1 && type != 2){
				alert("请选择设备类型！");return false;
			}

			if(back_time == ''){
				alert("请选择归还时间！");return false;
			}
			if( backtime <= time){
				alert("归还日期必须要大于申请日期！");return false;
			}
		}else if( action == 'sign' ){
			var higher_sign = $("input[name='higher_sign']").val();
			if(higher_sign == ''){
				alert("请负责人签字！");return false;
			}
		}else if( action == 'audit' ){
			var audit = $("input[name='audit']:checked").val();
			if(action == ''){
				
			}
			if(audit == undefined){
				alert("请审批该测试机申请！");return false;
			}else if( audit == '2' ){
				var audit_reason = $("input[name='audit_reason']").val();
				if( audit_reason == '' ){
					alert("请填写不同意通过该测试机申请的理由！");return false;
				}
			}
		}else if( action == 'send' ){
			var serial_number = $("input[name='serial_number']").val();
			if(serial_number == ''){
				alert("请填写设备序列号！");return false;
			}
		}

	}
</script>
</html>